﻿using System;
using System.Data;
using System.Web;
using System.Collections;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.ComponentModel;
using System.Collections.Generic;

using Newtonsoft.Json;
  
using XinBang.Util;
using XinBang.Entity;
using XinBang.ShoppingCart;

namespace XinBang.Web
{
    /// <summary>
    /// ShopService 的摘要说明
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [ToolboxItem(false)]
    public class ShopService : System.Web.Services.WebService
    {

        [WebMethod]
        public string HelloWorld()
        {
            return "Hello World";
        }

        [WebMethod(EnableSession = true)]
        public string GetShoppingCart()
        {
            IList<RecordUtil.ShoppingCartRecord> records = RecordUtil.ConvertShoppingCartToRecord();
            return JavaScriptConvert.SerializeObject(records);
        }

        [WebMethod(EnableSession = true)]
        public string DeleteRecord(string id)
        {
            Cart cart = Cart.GetShoppingCart();
            cart.RemoveGoodsFromCart(Convert.ToInt32(id));
            return string.Format("{flag:{0}}",true);
        }

        [WebMethod(EnableSession=true)]
        public string ClearCart()
        {
            Cart cart = Cart.GetShoppingCart();
            cart.ClearShoppingCart();
            return string.Empty;
        } 
    }
}
